/*
 * Copyright (C) 2010-2011 Graz University of Technology, Austria. All Rights reserved. 
 *
 * Contact: Simone Kopeinik <simone.kopeinik@tugraz.at>
 * 	   Graz University of Technology, Knowledge Management Institute, Brückenkopfgasse 1/6, 8020 Graz 	
 * 	   <http://www.kmi.tugraz.at/>
 * 
 * This software is part of the TARGET platform developed by the
 * TARGET EC-funded project www.reachyourtarget.org
 *
 * This software is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * The GNU General Public License is available at <http://www.gnu.org/licenses/>.
 *
 */
package at.tugraz.kmi.css.analyzer;

import java.util.HashSet;
import java.util.List;
import java.util.ServiceLoader;
import java.util.Set;

import net.guts.gui.application.AbstractApplication;
import at.tugraz.kmi.css.cbkst2.prereq.PrerequesiteOrderSetModule;
import at.tugraz.kmi.css.cbkst2.prereq.io.IOConfigurationModule;
import at.tugraz.kmi.css.cbkst2.prereq.structurevis.VisConfigurationModule;

import com.google.inject.Module;

/**
 * The main class of the application. Use the main method to start the
 * Competence Analyzer Tool.
 * 
 * @author Georg Öttl
 * 
 */
public class CompetenceAnalyzerMain extends AbstractApplication {

	public static void main(String[] args) {
		new CompetenceAnalyzerMain().launch(args);
	}

	@Override
	protected void initModules(String[] args, List<Module> modules) {
		modules.addAll(minimalModules());
	}

	Set<Module> minimalModules() {
		Set<Module> modules = new HashSet<Module>();

		// Minimal module configuration dependencies needed.
		modules.add(new CompetenceAnalyzerModule());
		modules.add(new PrerequesiteOrderSetModule());
		modules.add(new IOConfigurationModule());
		modules.add(new VisConfigurationModule());

		// Loading other optional modules from the META-INF descriptor.
		ServiceLoader<Module> modulesJars = ServiceLoader.load(Module.class);
		for (Module moduleJar : modulesJars) {
			boolean contained = false;
			for (Module module : modules) {
				if (moduleJar.getClass() == module.getClass()) {
					contained = true;
				}
			}
			if (!contained) {
				modules.add(moduleJar);
			}
		}
		return modules;
	}
}
